<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        var p = {
            name: "zs",
            age: 18,
            sex: "男",
            copy: function () {   //将当前对象拷贝一份
                //创建对象
                var temp = {};
                //复制对象 在copy中使用 this表示当前对象
                for (var k in this) {
                    temp[k] = this[k];
                }
                //返回对象
                return temp;
            }
        }
        var p2 = p.copy();
        p.name = 'ls';
        p.age = 20;
        p.sex = '女';
    </script>
</head>
<body>

</body>
</html>